Skip to content

Channelmanager: improve block connection logging#4586

Open
Alkamal01 wants to merge 2 commits intolightningdevkit:mainfrom
Alkamal01:block-connection-logging
Open

Channelmanager: improve block connection logging#4586
Alkamal01 wants to merge 2 commits intolightningdevkit:mainfrom
Alkamal01:block-connection-logging

Conversation

@Alkamal01
Copy link
Copy Markdown

Channelmanager: improve block connection logging

Fixes #2348. Supersedes #4420.

best_block_updated was logging at TRACE, making it impossible to track chain tip progress without enabling full trace logging. This upgrades it to INFO.

Also adds per-txid DEBUG logs in transactions_confirmed so individual transactions triggering channel updates are visible at a useful log level.

The original PR #4420 also added an INFO log in filtered_block_connected, but that duplicates the one in best_block_updated (which filtered_block_connected calls directly). That log is left out here.

Upgrade best_block_updated log from TRACE to INFO so chain tip
updates are visible without enabling full trace logging.

Add per-txid DEBUG logs in transactions_confirmed to make it easier
to identify which transactions triggered channel updates.
@ldk-reviews-bot
Copy link
Copy Markdown

ldk-reviews-bot commented May 2, 2026

I've assigned @valentinewallace as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

Comment on lines +15971 to +15973
for (_, tx) in txdata.iter() {
log_debug!(self.logger, "Confirmed transaction {} in block {} at height {}", tx.compute_txid(), block_hash, height);
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compute_txid() performs a double-SHA256 over the serialized transaction, and the log_given_level! macro evaluates its arguments unconditionally (the level check is inside the Logger::log implementation, not before argument evaluation). This means the loop runs and hashes every transaction even when the logger's level is above DEBUG.

Consider either:

  1. Guarding the loop behind a level check, or
  2. Folding these per-txid details into the existing TRACE log, or
  3. Using a lazy wrapper (e.g., a Display impl that computes on fmt) — though this still wouldn't avoid the loop itself.

While txdata only contains matching transactions (not the full block), computing txids unconditionally on every block connection is unnecessary overhead for users who don't have DEBUG enabled.

@ldk-claude-review-bot
Copy link
Copy Markdown
Collaborator

ldk-claude-review-bot commented May 2, 2026

Both prior issues are resolved in the latest commit:

  1. Transaction type path (prior comment on line 15971): Fixed — now uses Transaction directly (in scope from line 24) instead of the private chain::transaction::Transaction path.

  2. Unconditional compute_txid() (prior comment on line 15979): Fixed — the LazyTxid wrapper defers compute_txid() to the Display::fmt implementation. Since format_args! captures a reference to LazyTxid without invoking Display::fmt, and the Logger::log method only formats the message when the level check passes, the double-SHA256 is only computed when DEBUG logging is actually enabled.

No new issues found. The code is clean.

No issues found.

Both previously flagged issues have been addressed in the latest commit (985a82bb):

  • The Transaction type reference now uses the in-scope import instead of a private module path.
  • compute_txid() is correctly deferred via the LazyTxid Display wrapper, avoiding unnecessary hashing when DEBUG is disabled.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.16%. Comparing base (6573d42) to head (985a82b).
⚠️ Report is 32 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4586      +/-   ##
==========================================
+ Coverage   86.99%   87.16%   +0.17%     
==========================================
  Files         163      161       -2     
  Lines      109008   109266     +258     
  Branches   109008   109266     +258     
==========================================
+ Hits        94828    95247     +419     
+ Misses      11696    11544     -152     
+ Partials     2484     2475       -9     
Flag Coverage Δ
fuzzing ?
fuzzing-fake-hashes 31.21% <100.00%> (?)
fuzzing-real-hashes 22.94% <100.00%> (?)
tests 86.23% <100.00%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread lightning/src/ln/channelmanager.rs Outdated

let block_hash = header.block_hash();
log_trace!(self.logger, "{} transactions included in block {} at height {} provided", txdata.len(), block_hash, height);
struct LazyTxid<'a>(&'a chain::transaction::Transaction);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chain::transaction::Transaction references a private import — chain/transaction.rs has use bitcoin::transaction::Transaction; (no pub), so this name is not accessible from outside that module. This should fail to compile with error[E0603]: import 'Transaction' is private.

Transaction is already imported at line 24 of this file via use bitcoin::transaction::Transaction;, so the fix is simply:

Suggested change
struct LazyTxid<'a>(&'a chain::transaction::Transaction);
struct LazyTxid<'a>(&'a Transaction);

…gging

Use a lazy Display wrapper to format confirmed txids, preventing unconditional hashing when DEBUG logging is disabled.
@Alkamal01 Alkamal01 force-pushed the block-connection-logging branch from d78977d to 985a82b Compare May 3, 2026 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve block connection logging

3 participants